function AddOrDeleteRow(element,gridid){
	var ctrlid = new String(element.parentNode.id);
	var parts = ctrlid.split('_');
	var cellsid = parts[0] + '_' + parts[1] + '_' + parts[2] + '_' + parts[3] + '_' + 'cells';
	if(element.checked){
		document.getElementById(cellsid).style.visibility='visible';		
	}else{
		if(allowDelete(element)){
			document.getElementById(cellsid).style.visibility='hidden';
		}else{
			element.checked=true;
		}	
	}
	//alert("the current element is " + document.getElementById(cellsid).id);
	
	var nextRowNumber= 1 + parseInt(parts[3]);
	var nextRowid = parts[0] + '_' + parts[1] + '_' + parts[2] + '_' + nextRowNumber;
	if(element.checked && nextRowNumber<getRows(gridid) && document.getElementById(nextRowid).style.visibility=='hidden'){
		document.getElementById(nextRowid).style.visibility='visible';
		//alert("the next element is " + document.getElementById(nexRowid).id);	
	}
}

function packGridValue(gridid){
	var rows = getRows(gridid);
	var cols = getCols(gridid);
	var checked=0;
	for(k=0; k<rows; k++){
		if(document.getElementById(gridid+'_'+k).checked){
			checked ++;
			break;
		}
	}
	if(checked==0){
		////alert(gridid + " no checked items");
		document.getElementById(gridid+'_0').checked=true;
		document.getElementById(gridid+'_0').value=getNullValue(gridid);
	}else{
		for(i=0;i<rows;i++){
			var values= '';
			var value = '';
			for(j=0;j<cols;j++){
				value = document.getElementById(gridid+'_'+i+'_'+j).value;
				values = values + '`' + value.replace('`','\'');
			}
			document.getElementById(gridid+'_'+i).value = values.substr(1);
			//alert(gridid + "." + i + ".value=" + document.getElementById(gridid+'_'+i).value);
		}
	}
}

function getRows(gridid){
	var str = gridid+'_grid_rows';
	return document.getElementById(str).value;
}

function getCols(gridid){
	var str = gridid+'_grid_cols';
	return document.getElementById(str).value;
}

function getNullValue(gridid){
	var cols = getCols(gridid);
	var value = '';
	for(i=0; i<cols; i++){
		value += '`';
	}
	return value;
}

function allowDelete(element){
	//var elementId = new String(element.id);
	//alert("the current element is " + elementId);
	return true;
}

